Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

syncer: fix the gtid purged error when switching pos replication to gtid (#2094) #2104

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #2094

What problem does this PR solve?

Fix #1814
In #1723 we support switching position replication to gtid replication by combining previous GTID sets and their events in binlog files. However, if there are some gtid events that are purged, the switching progress will fail.

What is changed and how it works?

According to MySQL's official document 1

The set of transactions that can be found in the binary logs at any given time is equal to GTID_SUBTRACT(@@GLOBAL.gtid_executed, @@GLOBAL.gtid_purged); that is, to all transactions in the binary log that have not yet been purged.

and MySQL's official document 2

The set of GTIDs in the gtid_purged system variable (@@GLOBAL.gtid_purged) contains the GTIDs of all the transactions that have been committed on the server, but do not exist in any binary log file on the server. gtid_purged is a subset of gtid_executed. The following categories of GTIDs are in gtid_purged:

* GTIDs of replicated transactions that were committed with binary logging disabled on the replica.
* GTIDs of transactions that were written to a binary log file that has now been purged.

Gsets of gtid_purged are not in any binlog files but they are contained in gtid_executed. This can explain two things:

  1. We can't get binlog events in gtid_purged, even if we continue the way of position replication.
  2. The method of replication to current gtid_executed won't make the situation better. Upstream MySQL may still purge binlogs when we trying to catch events to gtid_executed.

So we can directly add gtid_purged in adjusted gtid sets to avoid MySQL error.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    Use a slave MySQL whose previous gtids starts from 5 to test whether this PR works.

Related changes

  • Need to cherry-pick to the release branch
  • Need to be included in the release note

@ti-chi-bot
Copy link
Member Author

ti-chi-bot commented Sep 8, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Ehco1996
  • lance6716

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added size/M status/PTAL This PR is ready for review. Add this label back after committing new changes type/cherry-pick-for-release-2.0 labels Sep 8, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 One reviewer already commented LGTM label Sep 8, 2021
@ti-chi-bot ti-chi-bot added status/LGT2 Two reviewers already commented LGTM, ready for merge and removed status/LGT1 One reviewer already commented LGTM labels Sep 9, 2021
@Ehco1996
Copy link
Contributor

Ehco1996 commented Sep 9, 2021

/merge

@ti-chi-bot
Copy link
Member Author

This pull request has been accepted and is ready to merge.

Commit hash: 704999b

@ti-chi-bot ti-chi-bot merged commit 497f57f into pingcap:release-2.0 Sep 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
size/M status/can-merge status/LGT2 Two reviewers already commented LGTM, ready for merge status/PTAL This PR is ready for review. Add this label back after committing new changes type/cherry-pick-for-release-2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants